import { createRouter, createWebHistory } from "vue-router";

/*
3类路由（一级路由）
  |-- 带底部 导航栏 （首页、分类、购物车、我的）
  |-- 购物车
  |-- 登录
*/

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "root",
      // 基座组件，用来加载子路由
      component: () => import("@/components/BaseShell.vue"),
      redirect: { name: "home" },
      children: [
        {
          name: "home",
          path: "home",
          component: () => import("@/views/Home/index.vue"),
        },
        {
          name: "shop",
          path: "shop",
          component: () => import("@/views/ShopList/index.vue"),
        },
        {
          name: "my",
          path: "my",
          component: () => import("@/views/My/index.vue"),
        },
        {
          path: "cat",
          name: "cat",
          component: () => import("@/components/BaseCat.vue"),
          children: [
            {
              name: "cat-pay",
              path: "catPay",
              component: () => import("@/views/CatPay/index.vue"),
            },
            {
              name: "cat-ctrl",
              path: "catCtrl",
              component: () => import("@/views/CatCtrl/index.vue"),
            },
          ],
        },
      ],
    },
    {
      path: "/login",
      name: "login",
      component: () => import("@/views/Login/index.vue"),
    },
    {
      path: "/detail/:id",
      name: "detail",
      component: () => import("@/views/Detail/index.vue"),
      props: true,
    },
  ],
});

export default router;
